package com.fortune.service.impl;

import com.faneui.common.exception.BusinessException;
import com.fortune.dal.dao.DebtDAO;
import com.fortune.dal.model.Debt;
import com.fortune.service.DebtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DebtServiceImpl implements DebtService {

    @Autowired
    private DebtDAO debtDAO;

    @Override
    public void addDebt(Debt debt) throws BusinessException {
        try {
            debtDAO.insert(debt);
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void modifyDebt(Debt debt) throws BusinessException {
        try {
            debtDAO.updateById(debt);
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void deleteDebt(Integer debtId) throws BusinessException {
        try{
            debtDAO.deleteById(debtId) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public Debt queryDebt(Integer debtId) throws BusinessException {
        Debt c = null;
        try {
            c = debtDAO.queryById(debtId);
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return c;
    }

    @Override
    public List<Debt> queryDebtList(Debt debt) throws BusinessException {
        List<Debt> list = null;
        try {
            list = debtDAO.queryByModel(debt);
        } catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return list;
    }
}
